/**
* Created by wl
* 项目管理>持有中-添加页
*/
<template>
    <div>
        <div class="right right__detail">
            <div class="ca-align-right">
                <div class="ca-head-fixed">
                    <el-button type="primary" @click="saveInfo">保存</el-button>
                    <el-button  @click="exit">退出</el-button>
                </div>
            </div>
            <csHeader @headerInfo="headerInfo"></csHeader>
            <csProjectDetails @detailInfo="detailInfo" @region="getRegion"></csProjectDetails>
            <csProjectManager @managerInfo="managerInfo"></csProjectManager>
            <csKeyProtocol @protocolInfo="protocolInfo" @textInfo="textInfo"></csKeyProtocol>
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from './api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind } from '__service/utils';
    export default {
        data() {
            return {
                info: {},
                region: [],
                itemHoldTopDTO: {},
                itemHoldInfoEntity: {},
                itemHoldProtocolEntities: {},
                itemHoldTextEntity: [],
                itemHoldManagerEntities: [],
                itemId: '', //项目id
            }
        },
        watch: {
        },
        props: {},
        mounted() {
        },
        methods: {
            exit() {
                this.$confirm('是否退出', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning',
                    showClose: false,
                }).then(() => {
                    this.$router.push({name: 'invested-project'})
                })
            },
            headerInfo(itemHoldTopDTO) {
                this.itemHoldTopDTO = itemHoldTopDTO
            },
            detailInfo(itemHoldInfoEntity) {
                this.itemHoldInfoEntity = itemHoldInfoEntity
            },
            protocolInfo(itemHoldProtocolEntities) {
                this.itemHoldProtocolEntities = itemHoldProtocolEntities
            },
            textInfo(itemHoldTextEntity) {
                this.itemHoldTextEntity = itemHoldTextEntity
            },
            managerInfo(itemHoldManagerEntities) {
                this.itemHoldManagerEntities = itemHoldManagerEntities
            },
            getRegion(region) {
                this.region = region
            },
            async save() {
                // 添加小红点
                await addRemind({
                    dataId: this.itemId, // 业务id
                    dataTab: 0, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 2, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            saveInfo() {
                if (!this.itemHoldTopDTO.itemEntity.itemFullname) {
                    this.$message({
                        message: '请输入项目全称',
                        type: 'error',
                        center: true
                    });
                    return false;
                } else if (!this.itemHoldTopDTO.itemEntity.itemName) {
                    this.$message({
                        message: '请输入项目简称',
                        type: 'error',
                        center: true
                    });
                    return false;
                } else if (this.itemHoldTopDTO.itemIndustryEntity.length === 0) {
                    this.$message({
                        message: '请选择行业',
                        type: 'error',
                        center: true
                    });
                    return false;
                } else {
                    let query = {
                        itemHoldInfoEntity: this.itemHoldInfoEntity,
                        region: this.region,
                        itemHoldManagerEntities: this.itemHoldManagerEntities,
                        itemHoldProtocolEntities: this.itemHoldProtocolEntities,
                        itemHoldTextEntity: this.itemHoldTextEntity,
                        itemHoldTopDTO: this.itemHoldTopDTO,
                        itemId: null,
                        quasiItemId: this.$route.params.itemId === '-1' ? null : this.$route.params.itemId
                    }
                    apiHttp(api.ADD_INVESTED, query).then(ret=> {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                message: '数据添加成功！',
                                type: 'success',
                                center: true
                            });
                            this.itemId = ret.data
                            this.save()
                            this.$router.push({name: 'invested-project'})
                        }
                    })
                }
            },
        },
        components: {
            csHeader: require('./header/add'),
            csProjectDetails: require('./project-detail/project-details/edit'),
            csProjectManager: require('./project-detail/project-manager/edit'),
            csKeyProtocol: require('./project-detail/key-protocol/edit'),
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.save-btn {
    position:fixed;
    top: 80px;
    right: 10%;
    z-index: 999;
    
}
</style>

